package com.lock.subscribe.offlinepwd;

import com.lock.subscribe.util.SoUtil2;

public class OfflinePasswordSo2 {

	public static void main(String[] args) {
		String macs = getChangeMac("DE:A6:F9:5E:36:69", 1758211200);
		char[] macc = getCharMacArray(macs);
		System.out.println(macc);
	}

	public static long onePwd(int pwdType,long current_time, String mac, long startTime, long endTime) {
		String macs = getChangeMac(mac, current_time);
		char[] macc = getCharMacArray(macs);
		long start_tim = (startTime - current_time) /240;
		long duration = 0;
		long pwd = SoUtil2.invoke(pwdType, macc, current_time, start_tim, duration);
		return pwd;
	}
	public static long hourPwd(int pwdType,long current_time, String mac, long startTime, long endTime) {
		String macs = getChangeMac(mac, current_time);
		char[] macc = getCharMacArray(macs);
		long start_tim = (startTime - current_time) /240;
		long duration = (endTime - startTime) /3600;
		long pwd = SoUtil2.invoke(pwdType, macc, current_time, start_tim, duration);
		return pwd;
	}
	public static long dayPwd(int pwdType,long current_time, String mac, long startTime, long endTime) {
		String macs = getChangeMac(mac, current_time);
		char[] macc = getCharMacArray(macs);
		long start_tim = (startTime - current_time) / 480;
		long duration = (endTime - startTime) /86400;
		long pwd = SoUtil2.invoke(pwdType, macc, current_time, start_tim, duration);
		return pwd;
	}
	
	public static char[] getCharMacArray(String macString) {
		String[] macParts = macString.split(":");
		char[] mac = new char[macParts.length];
		for (int i = 0; i < macParts.length; i++) {
			mac[i] = (char) Integer.parseInt(macParts[i], 16);
		}
		return mac;
	}

	public static String getChangeMac(String mac, long timeStamp) {
		String result = "";
		String hexTime = Long.toHexString(timeStamp);
		String last = hexTime.substring(hexTime.length() - 2, hexTime.length()).toUpperCase();
		String second = hexTime.substring(hexTime.length() - 4, hexTime.length() - 2).toUpperCase();
		String[] macc = mac.split(":");
		macc[0]= second;
		macc[1]= last;
		result =String.join(":",macc);
		return result;
	}

}
